/**************************************************************************************
* Component of simpleRTJ regression tests.
**************************************************************************************
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL RTJ COMPUTING BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Created by:
*       RTJ Computing
**************************************************************************************/
public class TestByte
{
    public static void test() throws Exception
    {
       //test overwrap
       byte t = 127-1;
       t++;
       if (t != 127) throw new Exception("TB1");
       t++;
       if (t != -128) throw new Exception("TB2");

       //shift tests
       t = 4;
       t = (byte)(t << (byte)1);
       if (t != 8) throw new Exception("TB3");

       t = (byte)(t >> (byte)2);
       if (t != 2) throw new Exception("TB4");

       //division test
       t = 4;
       if (t >> 1 != t / 2) throw new Exception("TB5");
       if (t / 3 != 1) throw new Exception("TB6");
       if (t / 5 != 0) throw new Exception("TB7");

       //multiplication test
       if (t << 2 != t * 4) throw new Exception("TB8");
       if (t * 3 != 12) throw new Exception("TB9");

       //modulus test
       if (t % 3 != 1) throw new Exception("TB10");
       if (t % 4 != 0) throw new Exception("TB11");
       if (t % 5 != 4) throw new Exception("TB12");

       //unsigned right shift test
       t = -1;
       if (t >>> 4 == t >> 4) throw new Exception("TB13");

       //cast test
       t = 4;
       if ((float)t != 4.0F) throw new Exception("TB14");
       if ((int)t != 4) throw new Exception("TB15");
       t = -1;
       if ((int)t != 0xffffffff) throw new Exception("TB16");
       if ((short)t != (short)0xffff) throw new Exception("TB17");

       //addition test
       if (t + 1 != 0) throw new Exception("TB18");
       if (t + 2 != 1) throw new Exception("TB19");

       //subtraction test
       if (t - 1 != -2) throw new Exception("TB20");

       //bitoperations test
       t = 4;
       t = (byte)(t & (byte)5);
       if (t != 4) throw new Exception("TB21");
       t = (byte)(t | (byte)5);
       if (t != 5) throw new Exception("TB22");
       t = (byte)(t ^ (byte)9);
       if (t != 12) throw new Exception("TB23");

       //order of evaluation test
       t = 4;
       t = (byte)((t + (byte)2)/(byte)3);
       if (t != 2) throw new Exception("TB24");
       t = (byte)(t + t / (byte)2);
       if (t != 3) throw new Exception("TB25");
       t = (byte)((t + (byte)1) * (byte)2);
       if (t != 8) throw new Exception("TB26");
       t = (byte)(t - t/(byte)2);
       if (t != 4) throw new Exception("TB27");
       t = (byte)((byte)2 << t / (byte)4);
       if (t != 4) throw new Exception("TB28");
       t = (byte)(t & (byte)4 << (byte)2 / (byte)4);
       if (t != 4) throw new Exception("TB29");
       t = (byte)(t | (byte)5 << (byte)2 / (byte)4);
       if (t != 5) throw new Exception("TB30");

       //assignment
       t = 9;
       t += (t=3);
       if (t != 12) throw new Exception("TB31");
       t = 9;
       t = (byte)(t + (t = (byte)3));
       if (t != 12) throw new Exception("TB32");
   }
}
